define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trades/assets/order/index' + location.search,
                    // add_url: 'trades/assets/order/add',
                    // edit_url: 'trades/assets/order/edit',
                    // del_url: 'trades/assets/order/del',
                    // multi_url: 'trades/assets/order/multi',
                    // import_url: 'trades/assets/order/import',
                    table: 'activity_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'orderid', title: __('Orderid'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount')},
                        //{field: 'paytype', title: __('Paytype')},
                        {field: 'paytype_text', title: __('Paytype'), operate: false,formatter:function(value,row){
                                if (row['paytype'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else {
                                    return '<span style="color:black">'+value+'</span>';
                                }
                            }
                        },
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'ordertype', title: __('Ordertype')},
                        {field: 'ordertype_text', title: __('Ordertype'), operate: false,formatter:function(value,row){
                                if (row['ordertype'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else {
                                    return '<span style="color:black">'+value+'</span>';
                                }
                            }
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            buttons: [
                        {
                            name: 'detail',
                            text: '详情',
                            icon: 'fa fa-folder-o',
                            classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                            url: 'trades/assets/order/detail?ids={ids}',
                        },
                      ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});